import QtQuick 2.0
import QtQuick.Window 2.12
import QtQuick.Controls 2.14
import Qt.labs.qmlmodels 1.0
import TransferSocket 1.0

Rectangle{
    width: parent.width
    height: parent.height
//    color: "#e0e0e0"
//    border.color: "black"
//    Component.onCompleted{
        function updatesocketname(){
            gsocketname = TransferSocket.socketName()
            let data = {socketname:gsocketname}
            var x = 1;
            for(let i =0;deviceModel.count;i++){
                if(deviceModel.get(i).gsocketname === gsocketname){
                    x = 0;
                    break;
                }
            }
            if(x === 1){
                deviceModel.append(data)
            }
        }
//    }

    Row {
        id:row1
        width: parent.width
        height: unit
        Rectangle{
            id:deviceheader
            width:unit*5
            height: unit
            color: "#e0e0e0"
            Text{
                anchors.centerIn: parent
                font.pointSize: 10
                text: "设备名(套接字名)"

            }
            Component.onCompleted: {
                console.log("============socketname")
            }
        }
        Rectangle{
            id:check
            anchors.topMargin: 5
            width: unit*4
            height:unit
            anchors.left: deviceheader.right
            color: "#e0e0e0"
            Text{
                anchors.centerIn: parent
                font.pointSize: 10
                text:"选择"
            }
            Component.onCompleted: {
                console.log("============check")
            }
        }
    }
    Row{
        id:row2
        anchors.top: row1.bottom
        width: parent.width
        height: parent.height-unit
        ListModel{
            id:deviceModel
            ListElement{
                gsocketname:"socketname"
            }
        }
        ListView{
            id:devicelist
            model:deviceModel
            width: parent.width
            height: parent.height
            spacing: 3
            delegate: DevRow{
                dUnit:unit
                socketname: gsocketname
            }
        }
    }
    Connections{
        target: TransferSocket
//        function updatesocketname(){
//            gsocketname = TransferSocket.socketName()
//        }
    }
}
